import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class MaxQueue {
    Queue<Integer> q;
    Deque<Integer> dq;

    public MaxQueue() {
        q = new LinkedList<>();
        dq = new LinkedList<>();
    }

    public int max_value() {
        if (q.isEmpty())
            return -1;
        return dq.peekFirst();
    }

    public void push_back(int value) {
        q.add(value);
        while (!dq.isEmpty() && dq.peekLast() < value) {
            dq.pollLast();
        }
        dq.addLast(value);
    }

    public int pop_front() {
        if (q.isEmpty())
            return -1;
        int val = q.poll();
        if (dq.peekFirst() == val)
            dq.pollFirst();
        return val;
    }
}
